// Variables that are used on both client and server

SWEP.HoldType			= "ar2"	
SWEP.PrintName			= "CSG-2000"			
SWEP.Author			= "Shs"
SWEP.Slot			= 4
SWEP.SlotPos			= 2
SWEP.Description		= "The Cheap Scare Gun 2,000. Beware!"
SWEP.Contact			= ""
SWEP.Purpose			= "Feel like your server is lacking.... creepiness? The Cheap Scare Gun 2,000 is the ultimate in scare technology, and is specifcally designed to scare the bejeezus out of people."
SWEP.Instructions		= "Left Click: Spawn either a gman, a stalker, or a shadow.\nRight Click: Toggle Between left click modes.\nUse+Left click: Make sounds where you're looking at.\nUse+Right click: Spawn a corpse"

SWEP.Spawnable			= false
SWEP.AdminSpawnable		= true

SWEP.ViewModel			= "models/weapons/v_rif_ak47.mdl"
SWEP.WorldModel			= "models/weapons/w_rif_ak47.mdl" 

SWEP.Primary.Recoil		= 0
SWEP.Primary.ClipSize		= -1
SWEP.Primary.DefaultClip	= 1
SWEP.Primary.Automatic		= false
SWEP.Primary.Delay		= 2
SWEP.Primary.Ammo		= "none"

SWEP.Secondary.Recoil		= 0
SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= 1
SWEP.Secondary.Automatic	= false
SWEP.Secondary.Delay		= 3
SWEP.Secondary.Ammo		= "none"

/*---------------------------------------------------------
			Primary Attack
---------------------------------------------------------*/
local loud = false	-- This turns on/off screaming when something flashes. True makes for more startling scares, while false makes for more subtle, but creepier ones.

util.PrecacheSound("ambient/machines/thumper_hit.wav")
util.PrecacheSound("npc/stalker/breathing3.wav")
util.PrecacheSound("npc/stalker/go_alert2a.wav")
util.PrecacheSound("ambient/creatures/town_scared_sob2.wav")
util.PrecacheSound("ambient/creatures/town_scared_sob1.wav")

util.PrecacheSound("ambient/atmosphere/ambience_base.wav")
util.PrecacheSound("ambient/atmosphere/hole_amb3.wav")
util.PrecacheSound("ambient/atmosphere/Drone1LP.wav")
util.PrecacheSound("ambient/atmosphere/corridor.wav")
util.PrecacheSound("ambient/atmosphere/corridor2.wav")
util.PrecacheSound("ambient/atmosphere/metallic1.wav")
util.PrecacheSound("ambient/atmosphere/metallic2.wav")
util.PrecacheSound("ambient/atmosphere/tone_quiet.wav")
util.PrecacheSound("ambient/atmosphere/tone_alley.wav")
util.PrecacheSound("ambient/atmosphere/noise2.wav")
util.PrecacheSound("ambient/atmosphere/sewer_air1.wav")

util.PrecacheSound("vo/Citadel/gman_exit01.wav")
util.PrecacheSound("vo/Citadel/gman_exit03.wav")
util.PrecacheSound("npc/zombie/zo_attack1.wav")
util.PrecacheSound("ambient/voices/playground_memory.wav")
util.PrecacheSound("ambient/voices/f_scream1.wav")
util.PrecacheSound("ambient/materials/shipgroan3.wav")
util.PrecacheSound("ambient/voices/citizen_beaten3.wav")
util.PrecacheSound("ambient/materials/shipgroan1.wav")
util.PrecacheSound("ambient/voices/cough4.wav")
util.PrecacheSound("ambient/materials/creak5.wav")
util.PrecacheSound("ambient/materials/creaking.wav")
util.PrecacheSound("ambient/creatures/town_muffled_cry1.wav")
util.PrecacheSound("ambient/creatures/town_zombie_call1.wav")
util.PrecacheSound("ambient/creatures/town_child_scream1.wav")
util.PrecacheSound("ambient/creatures/flies4.wav")
util.PrecacheSound("CSG-sounds/scarysound1.wav")
util.PrecacheSound("CSG-sounds/scarysound2.wav")
util.PrecacheSound("CSG-sounds/scarysound3.wav")
util.PrecacheSound("CSG-sounds/scarysound4.wav")
util.PrecacheSound("CSG-sounds/scarysound5.wav")
util.PrecacheSound("CSG-sounds/scarysound6.wav")
util.PrecacheSound("CSG-sounds/scarysound7.wav")
util.PrecacheSound("CSG-sounds/scarysound8.wav")
util.PrecacheSound("CSG-sounds/scarysound9.wav")
util.PrecacheSound("CSG-sounds/scarysound10.wav")
util.PrecacheSound("CSG-sounds/scarysound11.wav")
util.PrecacheSound("ambient/creatures/town_moan1.wav")
util.PrecacheSound("CSG-sounds/scarysound12.wav")
-- eesh.

local sounder = 0
local mode = 1		-- Mode to start in.
local amb = false	-- Do not touch
local ambience = 0	-- Do not touch
local bonus = true

function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
if( self.Owner:KeyDown(IN_USE) == false ) then
if mode == 1 then
local trace = {}
trace.start = self.Owner:GetShootPos()
trace.endpos = trace.start + (self.Owner:GetAimVector() * 99999)
trace.filter = { self.Owner, self.Weapon, }
local tr = util.TraceLine( trace )
local newpos = tr.HitPos

local yikes = ents.Create("npc_stalker")
yikes:SetPos(newpos)
yikes:SetAngles(self.Owner:GetAngles())
yikes:Spawn()
yikes:Fire("kill", "", 0.15)
if loud == true then
yikes:EmitSound("npc/stalker/go_alert2a.wav", 150, 100)
else
yikes:EmitSound("ambient/machines/thumper_hit.wav", 100, 100)
end
yikes:EmitSound("npc/stalker/breathing3.wav", 150, 100)
end


if mode == 2 then
local trace = {}
trace.start = self.Owner:GetShootPos()
trace.endpos = trace.start + (self.Owner:GetAimVector() * 99999)
trace.filter = { self.Owner, self.Weapon }
local tr = util.TraceLine( trace )
local newpos = tr.HitPos

local yikes = ents.Create("npc_gman")
yikes:SetPos(newpos)
yikes:SetAngles(self.Owner:GetAngles())
yikes:Spawn()
yikes:Fire("kill", "", 0.1)
if loud == true then
yikes:EmitSound("npc/stalker/go_alert2a.wav", 150, 100)
else
yikes:EmitSound("ambient/machines/thumper_hit.wav", 100, 100)
end
yikes:EmitSound("npc/stalker/breathing3.wav", 100, 100)
end


if mode == 3 then
local trace = {}
trace.start = self.Owner:GetShootPos()
trace.endpos = trace.start + (self.Owner:GetAimVector() * 99999)
trace.filter = { self.Owner, self.Weapon, }
local tr = util.TraceLine( trace )
local newpos = tr.HitPos

local yikes = ents.Create("npc_citizen")
yikes:SetPos(newpos)
yikes:SetKeyValue("rendercolor", "", "0 0 0")
yikes:SetAngles(self.Owner:GetAngles())
yikes:Spawn()
yikes:Fire("kill", "", 0.07)
if loud == true then
yikes:EmitSound("npc/stalker/go_alert2a.wav", 150, 100)
else
yikes:EmitSound("ambient/machines/thumper_hit.wav", 100, 100)
end
yikes:EmitSound("npc/stalker/breathing3.wav", 100, 100)
end

if mode == 4 then
local trace = {}
trace.start = self.Owner:GetShootPos()
trace.endpos = trace.start + (self.Owner:GetAimVector() * 99999)
trace.filter = { self.Owner, self.Weapon }
local tr = util.TraceLine( trace )
local newpos = tr.HitPos

local mingebag = ents.Create("prop_ragdoll")
mingebag:SetKeyValue("origin", tostring(newpos))
mingebag:SetKeyValue("angles", tostring(self.Owner:GetAngles()))
mingebag:SetModel("models/Kleiner.mdl")
mingebag:Spawn()
mingebag:EmitSound("npc/stalker/go_alert2a.wav", 150, 100)
mingebag:Fire("kill", "", 0.07)

local mingebaggun = ents.Create("prop_physics")
mingebaggun:SetModel("models/weapons/w_physics.mdl")
mingebaggun:SetPos(mingebag:GetPos())
mingebaggun:SetAngles(self.Owner:GetAngles())
mingebaggun:Spawn()
mingebaggun:Fire("kill", "", 0.07)
end
end

if( self.Owner:KeyDown(IN_USE) ) then

local trace = {}
trace.start = self.Owner:GetShootPos()
trace.endpos = trace.start + (self.Owner:GetAimVector() * 99999)
trace.filter = { self.Owner, self.Weapon }
local tr = util.TraceLine( trace )
local newpos = tr.HitPos

-- Don't ask why I chose that name.
b695qe346 = ents.Create("info_target")
b695qe346:SetKeyValue("targetname", "b695qe346")
b695qe346:Spawn()
b695qe346:SetPos(newpos)
b695qe346:Fire("kill", "", 10)

local scary = math.random(1,27)

if scary == 1 then
b695qe346:EmitSound("vo/Citadel/gman_exit01.wav")
end

if scary == 2 then
b695qe346:EmitSound("vo/Citadel/gman_exit03.wav")
end

if scary == 3 then
b695qe346:EmitSound("npc/zombie/zo_attack1.wav")
end

if scary == 4 then
b695qe346:EmitSound("ambient/voices/playground_memory.wav")
end

if scary == 5 then
b695qe346:EmitSound("ambient/voices/f_scream1.wav")
end

if scary == 6 then
b695qe346:EmitSound("ambient/materials/shipgroan3.wav")
end

if scary == 7 then
b695qe346:EmitSound("ambient/voices/citizen_beaten3.wav")
end

if scary == 8 then
b695qe346:EmitSound("ambient/materials/shipgroan1.wav")
end

if scary == 9 then
b695qe346:EmitSound("ambient/voices/cough4.wav")
end

if scary == 10 then
b695qe346:EmitSound("ambient/materials/creak5.wav")
end

if scary == 11 then
b695qe346:EmitSound("ambient/materials/creaking.wav")
end

if scary == 12 then
b695qe346:EmitSound("ambient/creatures/town_muffled_cry1.wav")
end

if scary == 13 then
b695qe346:EmitSound("ambient/creatures/town_zombie_call1.wav")
end

if scary == 14 then
b695qe346:EmitSound("ambient/creatures/town_child_scream1.wav")
end

if scary == 15 then
b695qe346:EmitSound("ambient/creatures/flies4.wav")
end

if scary == 16 then
b695qe346:EmitSound("CSG-sounds/scarysound1.wav")
end

if scary == 17 then
b695qe346:EmitSound("CSG-sounds/scarysound2.wav")
end

if scary == 18 then
b695qe346:EmitSound("CSG-sounds/scarysound3.wav")
end

if scary == 19 then
b695qe346:EmitSound("CSG-sounds/scarysound4.wav")
end

if scary == 20 then
b695qe346:EmitSound("CSG-sounds/scarysound5.wav")
end

if scary == 21 then
b695qe346:EmitSound("CSG-sounds/scarysound6.wav")
end

if scary == 22 then
b695qe346:EmitSound("CSG-sounds/scarysound7.wav")
end

if scary == 23 then
b695qe346:EmitSound("CSG-sounds/scarysound8.wav")
end

if scary == 24 then
b695qe346:EmitSound("CSG-sounds/scarysound9.wav")
end

if scary == 25 then
b695qe346:EmitSound("CSG-sounds/scarysound10.wav")
end

if scary == 26 then
b695qe346:EmitSound("CSG-sounds/scarysound11.wav")
end

if scary == 27 then
b695qe346:EmitSound("CSG-sounds/scarysound12.wav")
end

if scary == 28 then
b695qe346:EmitSound("ambient/creatures/town_moan1.wav")
end
	end
		end

/*---------------------------------------------------------
			Secondary Attack
---------------------------------------------------------*/

function SWEP:SecondaryAttack()
self.Weapon:SetNextSecondaryFire( CurTime() + self.Secondary.Delay )
if( self.Owner:KeyDown(IN_USE) == false ) then

if mode == 1 then
mode = 2
self.Owner:PrintMessage( HUD_PRINTTALK, "Gman Mode")
elseif mode == 2 then
mode = 3
self.Owner:PrintMessage( HUD_PRINTTALK, "Shadow Mode")
elseif mode == 3 then
if bonus == false then
mode = 1
self.Owner:PrintMessage( HUD_PRINTTALK, "Stalker Mode")
else
mode = 4
self.Owner:PrintMessage( HUD_PRINTTALK, "Secret Mingebag Mode")
end
elseif mode == 4 then
mode = 1
self.Owner:PrintMessage( HUD_PRINTTALK, "Stalker Mode")
end
end

if( self.Owner:KeyDown(IN_USE) ) then
local body = math.random(1,3)
local trace = {}
trace.start = self.Owner:GetShootPos()
trace.endpos = trace.start + (self.Owner:GetAimVector() * 99999)
trace.filter = { self.Owner, self.Weapon }
local tr = util.TraceLine( trace )
local newpos = tr.HitPos

local corpse = ents.Create("prop_ragdoll")
if body == 1 then
corpse:SetModel("models/Humans/corpse1.mdl")
end

if body == 2 then
corpse:SetModel("models/Humans/charple01.mdl")
end

if body == 3 then
corpse:SetModel("models/Humans/charple02.mdl")
end
corpse:SetKeyValue("origin", tostring(newpos))
corpse:SetKeyValue("angles", tostring(self.Owner:GetAngles()))
corpse:Spawn()
corpse:EmitSound("ambient/creatures/town_scared_sob"..math.random(1,2)..".wav")
corpse:Fire("kill", "", 5)
end
	end

/*---------------------------------------------------------
			Deploy
---------------------------------------------------------*/

function SWEP:Deploy()
if (SERVER) then
self.Owner:SetMaterial("sprites/heatwave")
self.Weapon:SetMaterial("sprites/heatwave")
self.Owner:Fire("addoutput", "rendermode 11", 0)
self.Weapon:Fire("alpha", 0, 0)
self.Owner:Fire("alpha", 0, 0)
self.Weapon:SetKeyValue("renderamt", "0")
self.Owner:SetKeyValue("renderamt", "0")
end
return true
end

/*---------------------------------------------------------
			Holster
---------------------------------------------------------*/

function SWEP:Holster()
if (SERVER) then
self.Owner:SetMaterial("")
self.Weapon:SetMaterial("")
self.Owner:Fire("addoutput", "rendermode 2", 0)
self.Weapon:Fire("alpha", 255, 0)
self.Owner:Fire("alpha", 255, 0)
self.Weapon:SetKeyValue("renderamt", "255")
self.Owner:SetKeyValue("renderamt", "255")
end
return true
end